<?
ob_start(); 
include("common/header.html");
include("common/left.html");
$out_html=ob_get_contents();
ob_end_clean();
include("class/BillRecord.php");
include("class/OrderRecord.php");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$id=abs($_REQUEST['id']);
$lid=$_REQUEST['lid'];
$tid=$_REQUEST['tid'];
$r=array();

$flag = isset($_GET['flag']) && $_GET['flag']==1 ? 1 : 0;
$payType = isset($_GET['pay']) ? intval($_GET['pay']) : '0|1|2';
$br      = new BillRecord($id, $s, $flag, $payType);

$r=$br->_detail($lid,$tid);
$b_info=$br->info();
$arr=array();
//print_r($r);
//exit;
foreach($r as $key=>$val){
	//print_r($val);
	$orderid=(string)$val->UUordernum;
	$sql="select * from pft_member_journal where orderid='".$orderid."' and fid='".$b_info['fid']."' and aid='".$b_info['aid']."' and daction=1 and dtype=0 and ptype=2 limit 1";
	$GLOBALS['le']->query($sql);
	$res=$GLOBALS['le']->fetch_assoc();
	if(!$res) continue;
	if((string)$val->UUaids==0){
		$totals[0]+=1;
		$totals[1]+=(string)$val->UUtnum;
		$totals[2]+=(string)$val->UUtotalmoney;
		$arr[]=$val;
	}else{
		$buyid=(string)$val->UUbuyid;
		$sql="select account from pft_member where id='$buyid' limit 1";
		$GLOBALS['le']->query($sql);
		$GLOBALS['le']->fetch_assoc();
		$ac1=$GLOBALS['le']->f('account');
		$pid=(string)$val->UUpid;
		$date=(string)$val->UUordertime;
		$mode=1;
		$ptype=0;
		$get_storage=0;
		$m=(string)$val->UUsellid;
		$date=substr($date,0,10);
		$tprice=$s->Dynamic_Price_And_Storage($ac1,$pid,$date,$mode,$ptype,$get_storage,$m,'','');
		$tprice=@simplexml_load_string($tprice);
		$val->UUtprice=$tprice->Rec->UUsprice;
		$val->UUtotalmoney=(string)$tprice->Rec->UUsprice*(string)$val->UUtnum;
		$totals[0]+=1;
		$totals[1]+=(string)$val->UUtnum;
		$totals[2]+=(string)$val->UUtotalmoney;
		$arr[]=$val;
	}
}
$r=$arr;
//print_r($r);
//exit;
/*导出EXCEL处理程序--begin-*/
include("ExcelHandle.php");
/*导出EXCEL处理程序--end*/
echo $out_html;
?>
<link type="text/css" rel="stylesheet" href="http://www.16u.com/manage/admin/dt/css/jquery.dataTables_themeroller.css" media="screen"/>
<link type="text/css" rel="stylesheet" href="http://www.16u.com/manage/admin/dt/css/themes/redmond/jquery-ui-1.7.2.custom.css" media="screen" />
<link type="text/css" rel="stylesheet" href="css/bill.css" media="screen" />
<script type="text/javascript" language="javascript" src="http://www.16u.com/manage/admin/dt/js/jquery.dataTables.min.js"></script>
<script>
	$(document).ready(function(){
		$('#tableDetail').dataTable({
			"bJQueryUI": true,
			"aaSorting": [[0,'desc']],
			"sPaginationType": "full_numbers"
		 });
	});
</script>
<div class="clay">
		<h3 class="mc_title">
			<span class="mctit_1"><span class="mctit_2">账单明细</span></span>
		</h3>
		<div class="head">
			<a class="fr excel" href="?id=<?=$_REQUEST['id']?>&lid=<?=$_REQUEST['lid']?>&tid=<?=$_REQUEST['pid']?>&act=fsettle1Excel">导出</a>
			<h3>
				<span>账单期间：<strong class="time"><?=$b_info['btime']?></strong> 至 <strong class="time"><?=$b_info['etime']?></strong></span>
			</h3>
			<p>账单统计：订单总数<em class="orange count"> <?=$totals[0]?> </em>单，门票总数<em class="green count"> <?=$totals[1]?> </em>张，总金额<em class="red count"> <?=$totals[2]/100?> </em>元</p>
		</div>
		<table id="tableDetail" class="detail">
			<thead>
				<tr>
					<th>订单号</th>
					<th class="name lows">产品所属(名称)</th>
					<th class="lows">下单日期</th>
					<th class="lows">使用日期</th>
					<th>结算价</th>
					<th>人数</th>
					<th>金额</th>
					<th>订单状态</th>
				</tr>
			</thead>
			<tbody>
				<?foreach($r as $row){?>
				<tr>
					<td><?=$row->UUordernum?></td>
					<td class="name rows"><?=$row->UUltitle?></br><?=$row->UUttitle?></td>
					<td class="rows"><?=substr($row->UUordertime,0,10)?></br><?=substr($row->UUordertime,10)?></td>
					<td class="rows"><?=substr($row->UUdtime,0,10)?></br><?=substr($row->UUdtime,10)?></td>
					<td><em class="red"><?=$row->UUtprice/100?></em></td>
					<td><em class="orange"><?=$row->UUtnum?></em></td>
					<td><em class="green"><?=$row->UUtotalmoney/100?></em></td>
					<td><?=OrderRecord::$UUstatusT[(string)$row->UUstatus]?></td>
				</tr>
				<?}?>
			</tbody>
		</table>
</div>
<?include("common/footer.html");?>